clear all

**Save to update later
global BS_fold_old = "$BS_fold"
global working_old = "$working"
global tempfold_old = "$tempfold"
global clean_old = "$clean"

global spec = "klme"
local spec = "$spec"

global tempfold = "$BS_fold/local9/" // **UPDATING TEMPFOLD TO BE A LOCAL FOLDER FOR EACH BOOTSTRAP;
global workingnew = "$BS_fold/local9/inputs/"
global BSfoldnew = "$BS_fold/local9/final/"
global cleannew = "$BS_fold/local9/inputs/"


***Move stuff to new working folder
use "$clean/prowess_wits_IO.dta", clear
save "$cleannew/prowess_wits_IO.dta", replace

use "$working/prowess_wits_estimation_qonly_klme.dta", clear
save "$workingnew/prowess_wits_estimation_qonly_klme.dta", replace

use "$working/first_last_years.dta", clear
save "$workingnew/first_last_years.dta", replace

use "$working/perpetual_inventory_capital.dta", clear
save "$workingnew/perpetual_inventory_capital.dta", replace

use "$working/wholesale_priceindex.dta", clear
save "$workingnew/wholesale_priceindex.dta", replace

global BS_fold = "$BSfoldnew" //  **UPDATING BS_fold TO BE A LOCAL FOLDER FOR EACH BOOTSTRAP;
global working = "$workingnew" //  **UPDATING working TO BE A LOCAL FOLDER FOR EACH BOOTSTRAP;
global clean = "$cleannew" //  **UPDATING working TO BE A LOCAL FOLDER FOR EACH BOOTSTRAP;



********************POINT ESTIMATES********************************************
do "$code/estimation/baseEst/09_cost_share_time_version_klme.do"
do "$code/estimation/baseEst/10_01_D_est_TFPQIV_CS_kl_nic4only.do"


global saveoutputs = "$working"
do "$code/estimation/flexible/data_work_CS_year_klme.do"
do "$code/estimation/flexible/data_work_CS_year_nic2_klme.do"
	

**NEED DIFFERENT TESTS WITH TIME: ALSO FIX THIS WITH REGSHELL + DECOMP
global datafiles = "decomposition_SS_CS_klme_by_year" 
do "$code/estimation/flexible/crosscheck_time.do"

global datafiles = "decomposition_SS_CS_klme_nic2_by_year" 
do "$code/estimation/flexible/crosscheck_time.do"


global datafiles = "decomposition_SS_CS_klme_by_year" 
global samplename = "CS_klme_year"
do "$code/estimation/flexible/reg_shell_short.do" 
	
global datafiles = "decomposition_SS_CS_klme_nic2_by_year" 
global samplename = "CS_klme_nic2_year"
do "$code/estimation/flexible/reg_shell_short.do" 
	


********************POINT ESTIMATES********************************************

***GRAB BS SAMPLES
do "$code/estimation/grabBS/09_CS_klme_time_grabBS.do"

***RUN BS
local bsamplesize = 100

forvalues bs = 1(1)`bsamplesize' {
	*******Decomposition Sample*******
	global bs = `bs'
	
	clear 
	use "$BS_fold_old/record/CS/klme/time/bssample_`bs'"
	
	save "$tempfold/bssample1", replace
	*Sample for second step (firm year)
	bysort co_code1 firm_year_bs year: generate count_thing = _n
	keep if count_thing==1
	keep co_code1 firm_year_bs year
	save "$tempfold/bssample2", replace


	do "$code/estimation/flexible/cost_share_time_version_klme_bs.do" 
	
	global saveoutputs = "$tempfold"
	do "$code/estimation/flexible/D_est_TFPQIV_CS_klme_nic4only_bs.do"
	
	global saveoutputs = "$tempfold"
	do "$code/estimation/flexible/data_work_CS_year_klme.do"
	do "$code/estimation/flexible/data_work_CS_year_nic2_klme.do"
	

	global datafiles = "decomposition_SS_CS_klme_by_year" 
	global samplename = "CS_klme_year"
	do "$code/estimation/flexible/reg_shell_short_time_bs.do" 
	
	global datafiles = "decomposition_SS_CS_klme_nic2_by_year" 
	global samplename = "CS_klme_nic2_year"
	do "$code/estimation/flexible/reg_shell_short_time_bs.do" 
	
}

global BS_fold = "$BS_fold_old" //  **UPDATING BS_fold TO BE THE MAIN PATH AGAIN;
global working = "$working_old" //  **UPDATING working TO BE THE MAIN PATH AGAIN;
global tempfold = "$tempfold_old"
global clean = "$clean_old"
